package com.juzi.wopu.service.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

import com.juzi.wopu.domain.OrderProduct;
import com.juzi.wopu.query.OrderProductQuery;
import com.juzi.wopu.service.IOrderProductService;

public class OrderProductServiceImpl extends BaseServiceImpl<OrderProduct> implements IOrderProductService{

	@Override
	public Map<String, String> getTotalCount(OrderProductQuery query) {
		Map<String, String> map=new HashMap<>();
		
		String sql="select sum(iNum),sum(iPrice) FROM tOrderProduct where 1=1 ";
		
		if(query.getBeginDate()!=null && query.getEndDate()!=null){
			SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			sql=sql+" and dtInsert > '"+dateFormat.format(query.getBeginDate())+
					"' and dtInsert < '"+dateFormat.format(query.getEndDate())+"'";
			
		}
		
		int totalNum=-1;
		double totalMoney=-1;
		ResultSet resultSet=BaseDao.executeQuerySql(sql);
		if(resultSet!=null){
			try {
				while(resultSet.next()){
					totalNum=resultSet.getInt(1);
					totalMoney=resultSet.getDouble(2);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		map.put("totalNum", totalNum+"");
		map.put("totalMoney", totalMoney+"");
		return map;
	}
}
